import { extend } from "vee-validate";
import { phoneReg, codeReg, passwordReg } from "../../utils/regExp";

//定义手机号校验规则
extend("phoneRequired", {
	validate(value) {
		return !!value;
	},
	message: "手机号不能为空",
	computesRequired: true//加上这个就会先验证表单，表单不通过不触发事件
});
extend("phone", {
	validate(value) {
		return phoneReg.test(value);
	},
	message: "手机号不规范"
});

//定义验证码校验规则
extend("codeRequired", {
	validate(value) {
		return !!value;
	},
	message: "验证码不能为空",
	computesRequired: true
});
extend("code", {
	validate(value) {
		return codeReg.test(value);
	},
	message: "验证码不规范"
});

//定义密码校验规则
extend("passwordRequired", {
	validate(value) {
		return !!value;
	},
	message: "密码不能为空",
	computesRequired: true
});
extend("password", {
	validate(value) {
		return passwordReg.test(value);
	},
	message: "密码不规范"
});

//定义确认密码校验规则
extend("rePasswordRequired", {
	validate(value) {
		return !!value;
	},
	message: "确认密码不能为空",
	computesRequired: true
});
extend("rePassword", {
	validate(value, [ password ]) {
		// console.log(arguments);
		return value === password;
	},
	message: "两次密码不正确"
});

//定义是否阅读文件的规则
extend("agrre", {
	validate(value) {
		return value;
	},
	message: "请先阅读相关文件",
	computesRequired: true
});
